package com.yc.sole.framework.mybatis.config;

import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import net.sf.jsqlparser.expression.Expression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yizuomin
 * @date 2023/2/13 14:40
 **/
@Configuration
public class DefaultTenantConfig {

    private static final String TENANT_ID_COLUMN = "tenant_id";

    @Bean
    @ConditionalOnMissingBean(TenantLineHandler.class)
    public TenantLineHandler tenantLineHandler() {
        return new TenantLineHandler() {
            @Override
            public Expression getTenantId() {
                return null;
            }

            //对应数据库列名
            @Override
            public String getTenantIdColumn() {
                // 对应数据库列名
                return TENANT_ID_COLUMN;
            }

            //需要忽略的表名,返回true表示忽略
            @Override
            public boolean ignoreTable(String tableName) {
                return true;
            }
        };
    }
}
